package com.chinatelecom.clientservice.service.client.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chinatelecom.clientservice.dao.client.PayEntryMapper;
import com.chinatelecom.clientservice.dao.client.PayModeMapper;
import com.chinatelecom.clientservice.dao.client.PayScensMapper;
import com.chinatelecom.clientservice.pojo.ExtGridReturn;
import com.chinatelecom.clientservice.pojo.ExtPager;
import com.chinatelecom.clientservice.pojo.client.PayEntry;
import com.chinatelecom.clientservice.pojo.client.PayEntryExample;
import com.chinatelecom.clientservice.pojo.client.PayMode;
import com.chinatelecom.clientservice.pojo.client.PayModeExample;
import com.chinatelecom.clientservice.pojo.client.PayScens;
import com.chinatelecom.clientservice.pojo.client.PayScensExample;
import com.chinatelecom.clientservice.service.client.PaymentService;

@Service
public class PaymentServiceImpl implements PaymentService {
	@Autowired
	private PayScensMapper payScensMapper;
	@Autowired
	private PayEntryMapper payEntryMapper;
	@Autowired
	private PayModeMapper payModeMapper;

	@Override
	public ExtGridReturn payScensList(PayScens payScens, ExtPager pager) {
		PayScensExample example = new PayScensExample();
		int count = payScensMapper.countByExample(null);
		List<PayScens> list = null;
		if (pager.getLimit() != null && pager.getStart() != null) {
			list = payScensMapper.selectByExample(example, new RowBounds(pager.getStart(), pager.getLimit()));
		} else {
			list = payScensMapper.selectByExample(example);
		}
		return new ExtGridReturn(count, list);
	}

	@Override
	public PayScens searchPaySences(String id) {
		return payScensMapper.selectByPrimaryKey(id);
	}

	@Override
	public int savePaySencens(PayScens payScens) throws Exception {
		int results = 0;
		if (StringUtils.isNoneBlank(payScens.getId())) {
			results = payScensMapper.updateByPrimaryKeySelective(payScens);
		} else {
			results = payScensMapper.insert(payScens);
		}
		return results;
	}

	@Override
	public ExtGridReturn payEntryList(PayEntry payEntry, ExtPager pager) {
		PayEntryExample example = new PayEntryExample();
		int count = payEntryMapper.countByExample(null);
		List<PayEntry> list = null;
		if (pager.getLimit() != null && pager.getStart() != null) {
			list = payEntryMapper.selectByExample(example, new RowBounds(pager.getStart(), pager.getLimit()));
		} else {
			list = payEntryMapper.selectByExample(example);
		}
		return new ExtGridReturn(count, list);
	}

	@Override
	public PayEntry searchPayEntry(String id) {
		return payEntryMapper.selectByPrimaryKey(id);
	}

	@Override
	public ExtGridReturn payModeList(PayMode payMode, ExtPager pager) {
		PayModeExample example = new PayModeExample();
		int count = payModeMapper.countByExample(null);
		List<PayMode> list = null;
		if (pager.getLimit() != null && pager.getStart() != null) {
			list = payModeMapper.selectByExample(example, new RowBounds(pager.getStart(), pager.getLimit()));
		} else {
			list = payModeMapper.selectByExample(example);
		}
		return new ExtGridReturn(count, list);
	}

	@Override
	public PayMode searchPayMode(String id) {
		return payModeMapper.selectByPrimaryKey(id);
	}

	@Override
	public void payModeListOfHelp(Map<String,Object> param, ExtPager pager) {
		payModeMapper.callGetPayMode(param);
		System.out.println(1);
	}

}
